package com.yunbiji.demo.controller;

import com.yunbiji.demo.dao.CnNoteDao;
import com.yunbiji.demo.entity.CnActivity;
import com.yunbiji.demo.entity.CnNote;
import com.yunbiji.demo.entity.CnShare;
import com.yunbiji.demo.service.CnActivityService;
import com.yunbiji.demo.service.CnNoteService;
import com.yunbiji.demo.service.CnNotebookService;
import com.yunbiji.demo.service.CnShareService;
import com.yunbiji.demo.service.impl.CnNoteServiceImpl;
import com.yunbiji.demo.util.NoteResult;
import com.yunbiji.demo.util.NoteUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * (CnNote)表控制层
 *
 * @author makejava
 * @since 2021-06-02 08:40:16
 */
@Controller
@RequestMapping(value = {"cnNote","/"})
public class CnNoteController {
    /**
     * 服务对象
     */
    @Resource
    private CnNoteService cnNoteService;
    private CnNoteDao cnNoteDao;
    private CnShareService cnShareService;


    @RequestMapping("/add.do")
    @ResponseBody
    public NoteResult<CnNote> execute1(String userId, String bookId, String title){
        NoteResult<CnNote> result = cnNoteService.insert(userId, bookId, title);
        return result;
    }

    @RequestMapping("/delete.do")
    @ResponseBody
    public NoteResult execute1(String noteId){
        NoteResult result=cnNoteService.deleteById(noteId);
        return result;
    }

    @RequestMapping("/load.do")
    @ResponseBody//以json格式返回数据
    public NoteResult<CnNote> execute2(String noteId){
        NoteResult<CnNote> result = cnNoteService.loadNote(noteId);
        return result;
    }

    @RequestMapping("/loads.do")
    @ResponseBody//以json格式返回
    public NoteResult<List<Map>> execute(String bookId){
        NoteResult<List<Map>> result = cnNoteService.loadBookNotes(bookId);
        return result;
    }

    @RequestMapping("/move.do")
    @ResponseBody
    public NoteResult<Object> execute(String noteId,String bookId){
        NoteResult result=cnNoteService.moveNote(noteId,bookId);
        return result;
    }

    @RequestMapping("/update.do")
    @ResponseBody
    public NoteResult<Object> execute(String noteId,String title,String body){
        NoteResult<Object>result= cnNoteService.update(noteId,title,body);
        return result;
    }

    @RequestMapping("/load_share")
    @ResponseBody
    public NoteResult<CnShare> execute3(String shareId){
        NoteResult<CnShare> result = cnShareService.loadShareNote(shareId);
        return result;
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    @ResponseBody
    public CnNote selectOne(String id) {
        return this.cnNoteService.queryById(id);
    }

}